﻿#region Header
// Copyright (c) 2015 OPEN TONE, Inc.
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
#endregion
using System;
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

namespace OpenXmlLib.Excel.Impl
{
	/// <summary>
	/// ISharedStringTable実装
	/// </summary>
	public class SharedStringTableImpl : ISharedStringTable
	{
		// SharedStringTablePartオブジェクト
		private readonly SharedStringTablePart sharedStringTablePart;

		/// <summary>
		/// 
		/// </summary>
		/// <see cref="ISharedStringTable.Workbook"/>
		public IWorkbook Workbook { get; private set; }

		/// <summary>
		/// コンストラクタ
		/// </summary>
		private SharedStringTableImpl() { }

		/// <summary>
		/// コンストラクタ
		/// </summary>
		/// <param name="workbook">IWorkbookオブジェクト</param>
		/// <param name="sharedStringTablePart">SharedStringTablePartオブジェクト</param>
		internal SharedStringTableImpl(
			IWorkbook workbook, SharedStringTablePart sharedStringTablePart)
		{
			this.Workbook = workbook;
			this.sharedStringTablePart = sharedStringTablePart;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="index"></param>
		/// <returns></returns>
		/// <see cref="ISharedStringTable.ElementAt"/>
		public String ElementAt(int index)
		{
			SharedStringTable sst = sharedStringTablePart.SharedStringTable;
			String value = sst.ElementAt(index).InnerText;
			return value;
		}
	}
}
